<?php

// $Id$


require_once($WSC->get_site_inc_dir().'modules/tangra_cms/_sys/tcms_admin_page_w_fctrl_ua.class.php');
require_once($WSC->get_site_inc_dir().'modules/tangra_cms/forms/image/image_form_ctrl.class.php');


class Image_Edit_WP extends TCMS_Admin_Page_W_FCtrl_UA {
	public function create_view($name = 'default') {
		$ret = new TCMS_Admin_Page_View($this, $name, 'modules/tangra_cms/pages/_image/');

		return $ret;
	}


	protected function create_form_ctrl() {
		$dbc = $this->get_dbc();
		$tvm = $this->get_tvm();

		$ret = new Image_Form_Ctrl('image', $tvm, $dbc, 'obj_id');

		return $ret;
	}


	protected function create_default_redir_view() {

		$content_id = $this->form_ctrl->get_permanent_external_param('content', true);
		if ($content_id) {
			$redir = new Redirect_Composer_Local($this->get__context(), 'admin/modules/tangra_cms/content_manage.php');
			$redir->add_param_pair('manage', $object->get_id());

		} else {
			$redir = new Redirect_Composer_Local($this->get__context(), $this->get_redir_on_success());
		}


		$redir_view = new Just_Headers_View();
		$redir_view->add_http_header($redir->get_location($this->get__context()));

		return $redir_view;
	}


	protected function on_add_new() {
		throw new Tangra_Module_Exception('Not supported.');
	}


	protected function on_received_id($object_id) {
		$context = $this->get__context();
		if ($context->exists_in_get('content') ) {
			$content_id = $content_id->get_from_get('content');
			tangra_if_not_int_throw_e($content_id);
			$this->form_ctrl->set_permanent_external_param('content', $content_id);
		}

		$dbc = $this->get_dbc();
		$image = new TCMS_Image_DBC();
		if ($image->load_by_id($dbc, $object_id)) {
			$this->export('orig_filename', $image->get_orig_filename());
		}

		$this->export('image_id', $object_id);
	}
}